﻿<cfcomponent>
<cfscript>
DB = 'chinalaohu';
dbt = 'auction';
domain = 'http://adio.chinalaohu.com';
</cfscript>

	<cffunction name="list" access="remote" returntype="any" returnFormat="json">
  <cfparam name="page" default="0">
  <cfscript>
	if (not isdefined('pagesize')){
	pagesize = 10;
	}
	//startrow = ;
	if (isdefined('preview') and preview eq 1){
		p = 1;
	}
	else {
		p = 0;
	}
	if (isdefined('auction') and auction eq 1){
		a = 1;
	}
	else {
		a = 0;
	}
	if (isdefined('deal') and deal eq 1){
		d = 1;
	}
	else {
		d = 0;
	}
	pad = p & a & d;
	
	if (isdefined('order')){
		switch(order){
			case 1:
				orderby = 'endtime ASC';
			  break;
			case 2:
				orderby = 'if(lastprice = 0,startprice,lastprice) DESC';
			  break;
			case 3:
				orderby = 'if(lastprice = 0,startprice,lastprice) ASC';
			  break;
			case 4:
				orderby = 'bids DESC';
			  break;
			default:
				orderby = 'aid DESC';
			  break;
		}
	}
	</cfscript>
  
  <cfquery datasource="#DB#" name="auctionrc">
  SELECT
  aid
  FROM
  auction
  WHERE 
	is_delete = 0 and atag > 0 AND prevtime <= #now()#
  <cfif isdefined('cateID') and (len(cateID) gt 0 AND cateID gt 0)>AND pcid=#cateID#</cfif>
  <cfif isdefined('pbid') and (len(pbid) gt 0 AND pbid gt 0)>AND pbid=#pbid#</cfif>
  <cfif isdefined('title') and len(title) gt 0>
  AND auction.auction like '%#title#%'
  </cfif>
  <cfif isdefined('sprice') and isnumeric(sprice)>
  AND if(lastprice = 0,startprice,lastprice) >= #sprice#
  </cfif>
  <cfif isdefined('eprice') and isnumeric(eprice)>
  AND if(lastprice = 0,startprice,lastprice) <= #eprice#
  </cfif>
  <cfswitch expression="#pad#">
  <cfcase value="100">
  AND starttime > #now()#<!---预展--->
  </cfcase>
  <cfcase value="010">
  AND starttime <= #now()# and endtime >= #now()#<!---竞拍--->
  </cfcase>
  <cfcase value="001">
  AND endtime <= #now()#<!---结标--->
  </cfcase>
  <cfcase value="110">
  AND endtime > #now()#<!---预展~结标--->
  </cfcase>
  <cfcase value="101">
  AND (starttime > #now()# OR endtime <= #now()#)<!---预展~结标--->
  </cfcase>
  <cfcase value="111">
  </cfcase>
  <cfcase value="000">
  </cfcase>
  </cfswitch>
  </cfquery>
  <cfdump var="#valuelist(auctionrc.aid)#">
	<cfquery datasource="#DB#" name="auctionlist"> 
  SELECT
  auction.aid,
  auction.atype,
  auction.atag,
  acode,
  auction.auction AS aname,
  auction.startprice,
  auction.oneprice,
  auction.lastprice,
  if(lastprice = 0,startprice,lastprice) as showprice,
  prevtime,
  starttime,
  endtime,
  auction_gallery.img_waterfall
  FROM
  auction
  INNER JOIN auction_gallery ON auction_gallery.agid = auction.agid
  WHERE 
	is_delete = 0 and atag > 0 AND prevtime <= #now()#
  <cfif isdefined('cateID') and (len(cateID) gt 0 AND cateID gt 0)>AND pcid=#cateID#</cfif>
  <cfif isdefined('pbid') and (len(pbid) gt 0 AND pbid gt 0)>AND pbid=#pbid#</cfif>
  <cfif isdefined('title') and len(title) gt 0>
  AND auction.auction like '%#title#%'
  </cfif>
  <cfif isdefined('sprice') and isnumeric(sprice)>
  AND if(lastprice = 0,startprice,lastprice) >= #sprice#
  </cfif>
  <cfif isdefined('eprice') and isnumeric(eprice)>
  AND if(lastprice = 0,startprice,lastprice) <= #eprice#
  </cfif>
  <cfswitch expression="#pad#">
  <cfcase value="100">
  AND starttime > #now()#<!---预展--->
  </cfcase>
  <cfcase value="010">
  AND starttime <= #now()# and endtime >= #now()#<!---竞拍--->
  </cfcase>
  <cfcase value="001">
  AND endtime <= #now()#<!---结标--->
  </cfcase>
  <cfcase value="110">
  AND endtime > #now()#<!---预展~结标--->
  </cfcase>
  <cfcase value="101">
  AND (starttime > #now()# OR endtime <= #now()#)<!---预展~结标--->
  </cfcase>
  <cfcase value="111">
  </cfcase>
  <cfcase value="000">
  </cfcase>
  </cfswitch>
  <cfif isdefined('orderby')>
  ORDER BY #orderby#
  </cfif>
  <cfif isdefined('page') and isnumeric(page)>limit #page * pagesize#,#pagesize#</cfif>
  </cfquery>
<cfdump var="#auctionlist#">


<!---会员相关--->  
<cfif isdefined('uuid') and isnumeric(uuid) and uuid gt 0>
<!---关注--->
<cfquery datasource="#DB#" name="usergzlist">
select aid
from user_concern
where uid = #uuid#
</cfquery>
<cfscript>
if (usergzlist.recordcount gt 0){
	usergz = valuelist(usergzlist.aid);
}
else {
	usergz = '';
}

</cfscript>
</cfif>
  
<cfscript>
rs = StructNew();
StructAppend(rs,{"success":1});
//是否过滤
/*1、竞价预展成交为全部时:000或111
2、没提交价格或是价格为空
3、父子过滤字段不存在或为空
4、没title或title长度为0*/
if (pad neq '000' and pad neq '111'){
	is_filter = 1;	
}
else if (isdefined('title') and len(title) gt 0){
	is_filter = 1;	
}
else if (isdefined('sprice') and len(sprice) gt 0 ){
	is_filter = 1;	
}
else if (isdefined('eprice') and len(eprice) gt 0 ){
	is_filter = 1;	
}
else if (isdefined('groupFilter') and len(groupFilter) gt 0 ){
	is_filter = 1;	
}
else if (isdefined('childFilter') and len(childFilter) gt 0 ){
	is_filter = 1;	
}
else if (isdefined('order') and order neq 0){
	is_filter = 1;
}

</cfscript>
<!---要求返回--->
<cfif isdefined('showSF') and showSF eq 1>
<cfscript>
filter = arraynew(1);
brandchild = arraynew(1);
</cfscript>
<cfquery datasource="#DB#" name="bandlist">
select pbid AS brandid,pbrands,platin,pcid
from pin_brands
<cfif isdefined('cateID') and (len(cateID) gt 0 AND cateID gt 0)>where pcid = #cateid#</cfif>
order by pborder asc
</cfquery>
<cfoutput query="bandlist">
<cfscript>
brandjson = {
	"name":pbrands,
  "value":brandid
};

arrayappend(brandchild,brandjson);

</cfscript>

</cfoutput>

<cfscript>

brandselect = {"name":"品牌","value":"pbid","child":brandchild};

//writedump(brand);
arrayappend(filter,brandselect);
priceselect = {"name":"价格区间",
"value":"showprice",
"child":[
{"name":"最小价格","value":"sprice"},
{"name":"最大价格","value":"eprice"}
]
};
arrayappend(filter,priceselect);

StructAppend(rs,{"filter":filter});
</cfscript>

<!---filter = [
	{"name":"品牌","value":"brand",
	"child":[{"name":"品牌"

]--->
<cfscript>
sort = [
{"name":"默认","value":"0"},
{"name":"结标时间","value":"1"},
{"name":"价格高的","value":"2"},
{"name":"价格底的","value":"3"},
{"name":"热门的","value":"4"}
];
StructAppend(rs,{"sort":sort});

</cfscript>
</cfif>
<cfscript>
StructAppend(rs,{"count":auctionrc.recordcount});
StructAppend(rs,{"serverTime":datetimeformat(now(),'yyyy-mm-dd HH:nn:ss')});
list = arraynew(1);
/*if (auctionrc.rc gt 0){
	//品牌才有图片
	if (not isdefined('is_filter')){
		arrayappend(list,{"imgUrl":"http://adio.chinalaohu.com/app/pic/home_darktea.jpg"});
	}
}*/
</cfscript>
<cfif auctionrc.recordcount gt 0 and not isdefined('is_filter')>
	<cfif isdefined('cateId') and cateId gt 0>
  	<!---分类图片显示--->
  	<cfquery datasource="#DB#" name="classimg">
    select pcimgurl
    from pin_class
    where pcid = #cateId#
    </cfquery>
    <cfscript>
		if (classimg.recordcount gt 0 and len(classimg.pcimgurl) gt 7){
			arrayappend(list,{"imgUrl":classimg.pcimgurl});
		}
		</cfscript>
  <cfelseif isdefined('brandId') and brandId gt 0>  
  	<!---分类图片显示--->
  	<cfquery datasource="#DB#" name="brandimg">
    select pbimgurl
    from pin_brands
    where pbid = #brandId#
    </cfquery>
    <cfscript>
		if (brandimg.recordcount gt 0 and len(brandimg.pbimgurl) gt 7){
			arrayappend(list,{"imgUrl":brandimg.pbimgurl});
		}
		</cfscript>
  </cfif>
  
  
</cfif>


<cfoutput query="auctionlist">
<cfscript>
attention = 0;
if (isdefined('usergz') and usergz neq ''){
	if (listfind(usergz,aid) gt 0){
		attention = 1;
	}
}
listjson = {
"aID":aid,
"auctionCode": acode,
"iconUrl":domain & img_waterfall,
"name":aname,
"price":showprice, 
"attention":attention
};
if (DateCompare(now(), endtime) gte 0){
	auctionType = 2;//成交
	structappend(listjson,{"dealTime":datetimeformat(endtime,'yyyy-mm-dd HH:nn')});
	
}
else if (DateCompare(now(), starttime) gte 0){
	auctionType = 1;//拍卖
	structappend(listjson,{"lastTime":datetimeformat(endtime,'yyyy-mm-dd HH:nn')});
	
}
else if (DateCompare(now(), prevtime) gte 0){
	auctionType = 0;//预展
	structappend(listjson,{"preSTime":datetimeformat(prevtime,'yyyy-mm-dd HH:nn')});
	structappend(listjson,{"preETme":datetimeformat(starttime,'yyyy-mm-dd HH:nn')});
}
else {
	auctionType = -1;//待展
	structappend(listjson,{"preSTime":datetimeformat(prevtime,'yyyy-mm-dd HH:nn')});
}

structappend(listjson,{"auctionType":auctionType});
/*showprice = lastprice;
if (showprice eq 0){
	showprice = startprice;
}
"preSTime":datetimeformat(prevtime,'yyyy-mm-dd HH:nn'),
"preETme":datetimeformat(starttime,'yyyy-mm-dd HH:nn'),
"lastTime":datetimeformat(endtime,'yyyy-mm-dd HH:nn'),

*/



arrayappend(list,listjson);
</cfscript>
</cfoutput>
<cfscript>
StructAppend(rs,{"list":list});
writedump(rs);

return rs;
</cfscript>
	</cffunction>
</cfcomponent>